﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OI_VS_CSharp {
    public class Program {
        static void Main(string[] args) {
            Console.WriteLine(LargestNumber(new int[] { 3, 30, 34, 5, 9 }));
        }

        public IList<string> TopKFrequent(string[] words, int k) {
            Dictionary<string, int> dict = new Dictionary<string, int>();
            foreach (string word in words) {
                if (dict.ContainsKey(word)) {
                    dict[word] += 1;
                } else {
                    dict[word] = 1;
                }
            }
            var ansdict = dict.OrderBy(r => r.Key).OrderByDescending(r => r.Value).Take(k).ToList();
            List<string> ret = new List<string>();
            foreach (var kp in ansdict) {
                ret.Add(kp.Key);
            }
            return ret;
        }

        public static string LargestNumber(int[] nums) {
            List<int> list = nums.ToList();
            list.Sort((x, y) => {
                long sx = 10, sy = 10;
                while (sx <= x) {
                    sx *= 10;
                }
                while (sy <= y) {
                    sy *= 10;
                }
                return (int)(sx * y + x - (sy * x + y));
            });
            if (list[0] == 0) return "0";
            string ret = "";
            foreach (var s in list) {
                ret += s.ToString();
            }
            return ret;
        }
    }
}